﻿package view.rongyu
{
    import com.greensock.*;
    import com.sh.game.display.*;
    import com.sh.game.util.*;
    import flash.display.*;
    import flash.geom.*;
    import manager.*;
    import morn.core.handlers.*;
    import view.expball.*;

    public class RYBallMagic extends Object
    {
        private var _con:Sprite;
        private var _ballboobmc:XMLMovieClip;
        private var _panelmc:XMLMovieClip;
        private var _expballmc:XMLMovieClip;
        private var _numItemCon:NumItemCon;
        private var _box1:Sprite;
        private var _load:int = 0;
        private var _panelH:int = 394;
        private var _panelW:int = 623;
        private var _func:Function;
        private var _closenum:Boolean;
        private var _playLock:Boolean = false;
        private var _numbackfunc:Function;
        private var ballx:int = 0;
        private var bally:int = 0;

        public function RYBallMagic(param1:Sprite, param2:Function, param3:Function = null)
        {
            this._con = param1;
            this._func = param2;
            this._numbackfunc = param3;
            XMLMcManager.instance.MainuiMc("ry_mb", this.ry_mbback);
            XMLMcManager.instance.MainuiMc("ry_q", this.ry_ballback);
            return;
        }// end function

        private function ry_ballback(param1:XMLMovieClip) : void
        {
            var _loc_2:String = this;
            var _loc_3:* = this._load + 1;
            _loc_2._load = _loc_3;
            this._ballboobmc = param1;
            this._con.addChild(this._ballboobmc);
            this._ballboobmc.visible = false;
            return;
        }// end function

        private function ry_qback(param1:XMLMovieClip) : void
        {
            var _loc_2:String = this;
            var _loc_3:* = this._load + 1;
            _loc_2._load = _loc_3;
            this._expballmc = param1;
            this._con.addChild(this._expballmc);
            this._expballmc.interval = 1000 / 15;
            this.ballx = this._box1.x + this._box1.width / 2 - this._expballmc.width / 2 + 90;
            this.bally = this._box1.y + this._box1.height / 2 - this._expballmc.height / 2;
            this._expballmc.x = this.ballx;
            this._expballmc.y = this.bally;
            this._expballmc.visible = false;
            return;
        }// end function

        private function ry_mbback(param1:XMLMovieClip) : void
        {
            var _loc_3:String = this;
            var _loc_4:* = this._load + 1;
            _loc_3._load = _loc_4;
            this._box1 = new Sprite();
            this._con.addChild(this._box1);
            this._panelmc = param1;
            this._box1.addChild(this._panelmc);
            this._panelmc.interval = 1000 / 15;
            var _loc_2:* = new Sprite();
            this._box1.addChild(_loc_2);
            _loc_2.y = 170;
            if (this._numbackfunc == null)
            {
                this._numItemCon = new NumItemCon(_loc_2, this.numover);
            }
            else
            {
                this._numItemCon = new NumItemCon(_loc_2, this._numbackfunc);
            }
            this._numItemCon.numUrl = "png.common.pow2_0000";
            XMLMcManager.instance.MainuiMc("ry_ball", this.ry_qback);
            this._con.visible = false;
            return;
        }// end function

        private function numover() : void
        {
            this._expballmc.alpha = 0;
            this._expballmc.scaleX = 0.5;
            this._expballmc.scaleY = 0.5;
            this.ballx = this._box1.x + this._box1.width / 2 - this._expballmc.width / 2 + 90;
            this.bally = this._box1.y + this._box1.height / 2 - this._expballmc.height / 2;
            this._expballmc.x = this._box1.x + this._box1.width / 2 - this._expballmc.width / 4 + 150;
            this._expballmc.y = this._box1.y + this._box1.height / 2 - this._expballmc.height / 4;
            if (this._expballmc.parent == null)
            {
                this._con.addChild(this._expballmc);
            }
            this._expballmc.visible = true;
            TweenLite.to(this._expballmc, 0.2, {delay:1.5, scaleX:1, scaleY:1, x:this.ballx, y:this.bally, alpha:1});
            TweenLite.to(this._box1, 0.2, {alpha:0, delay:1.5, scaleX:0, scaleY:0, x:this._box1.width / 2 + 200, y:this._box1.height / 2, onComplete:this.comScaleFunc});
            return;
        }// end function

        private function comScaleFunc() : void
        {
            var _loc_1:* = UIGlobel.pointsDic["guanwei"];
            TweenLite.to(this._expballmc, 0.2, {x:_loc_1.x - this._con.x - 244 / 2, y:_loc_1.y - this._con.y - 240 / 2, onComplete:this.comBoobFunc});
            return;
        }// end function

        private function comBoobFunc() : void
        {
            this._expballmc.visible = false;
            this._ballboobmc.visible = true;
            var _loc_1:* = UIGlobel.pointsDic["guanwei"];
            this._ballboobmc.x = _loc_1.x - this._con.x - 244 / 2;
            this._ballboobmc.y = _loc_1.y - this._con.y - 240 / 2;
            this._ballboobmc.playFromTo(-1, (this._ballboobmc.totalFrame - 1), new Handler(this.onComplete));
            return;
        }// end function

        public function playMovie(param1:int) : void
        {
            if (this._load != 3 || this._playLock)
            {
                if (this._func != null)
                {
                    this._func();
                }
                return;
            }
            if (param1 == 0)
            {
                return;
            }
            this.clearplay();
            this._playLock = true;
            this._con.visible = true;
            this._numItemCon.playNum(param1);
            return;
        }// end function

        private function onComplete() : void
        {
            if (this._func != null)
            {
                this._func();
            }
            this.clearplay();
            return;
        }// end function

        public function clearplay() : void
        {
            this._playLock = false;
            this._con.visible = false;
            this._box1.visible = true;
            this._box1.scaleX = 1;
            this._box1.scaleY = 1;
            this._box1.x = 0;
            this._box1.y = 0;
            this._box1.alpha = 1;
            this._numItemCon.clear();
            return;
        }// end function

        public function despose() : void
        {
            return;
        }// end function

    }
}
